<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- 引入样式 -->
    <script src="../../js/vue.js"></script>
    <script src="../../js/axios.min.js"></script>
    <script src="../../js/dayjs.min.js"></script>
    <link rel="stylesheet" href="../../plugins/element_UI/index.css">
    <script src="../../plugins/element_UI/index.js"></script>
</head>
<body>
<div id="app">
    <el-row class="el-search-row-d" style="text-align: center;height: 30px">
       账号信息修改
    </el-row>
    <el-row class="el-search-row-d" style="margin-left: 300px;width: 50%;" >
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" :label-position="labelPosition" label-width="100px" size="mini" class="demo-ruleForm" >
            <el-form-item label="职工姓名" prop="sffName">
                <el-input v-model="ruleForm.sffName"></el-input>
            </el-form-item>
            <el-form-item label="职工性别" prop="sffSex">
                <el-select v-model="ruleForm.sffSex" placeholder="请选择">
                    <el-option label="男"  value="1"  ></el-option>
                    <el-option label="女"  value="0"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="所属医院" prop="hospitalId">
                <el-select v-model="ruleForm.hospitalId" filterable placeholder="请选择" :disabled="true">
                    <el-option
                            v-for="item in hospitals"
                            :key="item.id"
                            :label="item.hosName"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="登录工号" prop="sffLoginNum">
                <el-input v-model="ruleForm.sffLoginNum" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item label="登录密码" prop="password">
                <el-input type="password" v-model="ruleForm.password"></el-input>
            </el-form-item>
            <el-form-item style="text-align: center;">
                <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>

            </el-form-item>
        </el-form>
    </el-row>

</div>
</body>
<script>
    let app = new Vue({
        el: '#app',
        data() {
            return {
                labelPosition: 'right',
                hospitals: [],
                ruleForm: JSON.parse(localStorage.getItem("user") || '[]'),
                rules: {
                    sffName: [
                        { required: true, message: '操作员姓名', trigger: 'blur' },
                        { min: 2, max: 9, message: '长度在 2 到 9 个字符', trigger: 'blur' }
                    ],
                    password: [
                        {required: true, message: '请输入登录密码', trigger: 'blur'},
                        {min: 3, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur'}
                    ]
                }
            }
        },
        methods: {
            init: function(){
                axios.post("http://" + window.location.host + '/hospital/select_list', {
                    hosName: ''
                }).then(res => {
                    this.hospitals = res.data.data;
                }).catch((e) => {
                    alert('获取数据失败');
                });
            },

            submitForm: function (ruleForm) {
                this.$refs[ruleForm].validate((valid) => {
                    if (valid) {
                        axios.post("http://" + window.location.host + '/pubStaffInfo/update_by_primary_key_selective', this.ruleForm).then(res => {
                            this.$message({
                                showClose: true,
                                message: '修改成功',
                                type: 'success'
                            });
                            this.$refs[ruleForm].resetFields();
                            this.dialogFormVisible = false
                            quit();
                            window.location.href = "http://"+window.location.host+"/"+'login.html'
                            localStorage.removeItem('user')
                        }).catch(function (error) {
                        });
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });

            }
        },
        created() {
            this.init()
        },
        mounted() {
        }
    });
</script>
</html>
